#ifndef CS488_MESH_HPP
#define CS488_MESH_HPP

#include <vector>
#include <iosfwd>
#include "primitive.hpp"
#include "algebra.hpp"
#include "ray.hpp"

// A polygonal mesh.
class Mesh : public Primitive {
public:
  Mesh(const std::vector<Point3D>& verts,
       const std::vector< std::vector<int> >& faces);
~Mesh(){ delete m_box;}
virtual bool RayIntersect(Ray ray, Intersection *intersection);
  typedef std::vector<int> Face;
  
private:
  std::vector<Point3D> m_verts;
  std::vector<Face> m_faces;
	NonhierBox *m_box;
	Point3D box_min;
	Point3D box_max;
	double box_size;
  bool check_same_normal(Point3D p1,Point3D p2,Point3D p3,Vector3D n);
	bool check_inside_box(Point3D pos);
  friend std::ostream& operator<<(std::ostream& out, const Mesh& mesh);
};

#endif
